package com.android.sharecar.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Main activity for settings.
 * just an navigate activity for subsettings.
 * @author xinyan
 *@date 2011-9-19
 */
public class ConfigureActivity extends Activity {
	public static final String TAG = "ConfigureActivity";

	// member vars
	private TextView mUserInfo; // var for userinfo setting.
	private TextView mStatus; // var for online status setting.
	private TextView mRequest; // var for request of pick ride setting.
	private TextView mPath; // var for work path setting.

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.configure);

		mPath = (TextView) findViewById(R.id.configure_tv_path);
		mRequest = (TextView) findViewById(R.id.configure_tv_request);
		mStatus = (TextView) findViewById(R.id.configure_tv_status);
		mUserInfo = (TextView) findViewById(R.id.configure_tv_userInfo);

		Log.v(TAG, "objects initiated, prepare to set listeners for text views");

		setListenersForMembers();

		Log.v(TAG, "listeners setting is done.");
	}

	/**
	 * This method will set the onTouch listeners for the textviews.
	 */
	private void setListenersForMembers() {
		mPath.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					Log.v(TAG, "path setting text view touched.");

					startActivity(new Intent(ConfigureActivity.this,
							ConfigPathActivity.class));

					Log.v(TAG, "skip into subsetting activity.");

					return true;
				}

				return false;
			}
		});

		mRequest.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					Log.v(TAG, "request setting text view touched.");

					new AlertDialog.Builder(ConfigureActivity.this)
							.setIcon(null)
							.setTitle(R.string.request)
							.setSingleChoiceItems(
									R.array.select_dialog_requestSetting, 0,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											/* User clicked on a radio button do some stuff */
										}
									})
							.setPositiveButton(R.string.positive,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											/* User clicked Yes so do some stuff */
										}
									})
							.setNegativeButton(R.string.cancel,
									new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {

											/* User clicked No so do some stuff */
											dialog.cancel();
										}
									}).create().show();

					Log.v(TAG, "skip into subsetting activity.");

					return true;
				}

				return false;
			}
		});

		mStatus.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					Log.v(TAG, "status setting text view touched.");

					new AlertDialog.Builder(ConfigureActivity.this)
							.setIcon(null)
							.setTitle(R.string.status)
							/*.setPositiveButton("确定", new DialogInterface.OnClickListener() {
								
								@Override
								public void onClick(DialogInterface dialog, int which) {
									// TODO Auto-generated method stub
									
								}
							})*/
							.setSingleChoiceItems(R.array.select_dialog_status,
									0, new DialogInterface.OnClickListener() {
										@Override
										public void onClick(
												DialogInterface dialog,
												int whichButton) {
											Log.v(TAG, "alert dialog clicked.");

											if (0 == whichButton) {
												Log.v(TAG,
														" you selected the online button.");

												// Do something........

												// then close it
												dialog.dismiss();
											} else if (1 == whichButton) {
												Log.v(TAG,
														"you selected the stealthy button.");

												// Do something........

												// then close it
												dialog.dismiss();

											}
										}
									}).create().show();

					Log.v(TAG, "alert dialog created.");

					return true;
				}

				return false;
			}
		});

		mUserInfo.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					Log.v(TAG, "userinfo setting text view touched.");

					startActivity(new Intent(ConfigureActivity.this,
							ConfigUserInfoActivity.class));

					Log.v(TAG, "skip into subsetting activity.");

					return true;
				}

				return false;
			}
		});
	}
}
